<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *-------------------------------------------------------------------
 * @creator 		: 
 * @finished date	: 2009/011/09
 * @description		: Tra ve tong so dong tu cau lenh sql tuong ung
 * @access	        : public
 *
 * @param string	: $str_where_clause       : menh de where
 * 					: 
 * @return string	: $obj_result->num_rows() : tong so dong
 *-------------------------------------------------------------------
 * @editor   	    : 
 * @finished date	: 
 * @editing content	: 
 *-------------------------------------------------------------------
 */	
function get_config_byid($nid)
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT *';
		$str_query .= ' FROM '.Fget_ap_table('tconfig').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.nid = '.$nid;
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
	
function get_mod_section_news_home()
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.nid,a.csection_news ';
		$str_query .= ' FROM '.Fget_ap_table('tsection_news').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.nstatus =	1';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
	


function get_mod_cat_news($nid_sec = '')
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.nid,a.ccat_news,a.cimage';
		$str_query .= ' FROM '.Fget_ap_table('tcat_news').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		if($nid_sec != '')
			$str_query .= ' AND a.nid_section_news = '.$nid_sec;
		$str_query .= ' AND a.nstatus =	1';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}

function get_mod_news($nid_sec = '')
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.cshort_content,a.cimage_thumb,a.nid';
		$str_query .= ' FROM '.Fget_ap_table('tnews').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		if($nid_sec != '')
			$str_query .= ' AND a.nid_section_news = '.$nid_sec;
		$str_query .= ' AND a.nstatus =	1';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$str_query .= ' LIMIT 0,1 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->row_array();
	}
	
function get_mod_news_other($nid_sec = '',$nid_news)
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.ctitle,a.cimage_thumb,a.nid as nid';
		$str_query .= ' FROM '.Fget_ap_table('tnews').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		if($nid_sec != '')
			$str_query .= ' AND a.nid_section_news = '.$nid_sec;
		$str_query .= ' AND a.nstatus =	1';
		$str_query .= ' AND a.nid !="'.$nid_news.'"';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$str_query .= ' LIMIT 0,5 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
function limit_str($str,$count)
{
	if(strlen($str)>$count)
		return substr($str,0,$count);
	else
		return $str;
	
}

function prefix_li()
{
	echo '<span style ="font-size:10px;color:#069"> >> </span>';

}


function get_mod_thongbao()
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.ctitle,a.nid,a.cindex';
		$str_query .= ' FROM '.Fget_ap_table('tarticle').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.nstatus =	1';
		$str_query .= ' AND a.nid_type =1';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$str_query .= ' LIMIT 0,10 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
	
function get_mod_video()
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.cwebname,a.cweblink,a.cindex';
		$str_query .= ' FROM '.Fget_ap_table('tweblink').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.cstatus =	1';
		$str_query .= ' AND a.ctype =	1';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$str_query .= ' LIMIT 0,10 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
	
function get_web_link()
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.cwebname,a.cweblink,a.cindex';
		$str_query .= ' FROM '.Fget_ap_table('tweblink').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.cstatus =	1';
		$str_query .= ' AND a.ctype =2';
		$str_query .= ' ORDER BY a.cindex+0 asc ';
		$str_query .= ' LIMIT 0,10 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
function get_news_byid_detail($nid)
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT *';
		$str_query .= ' FROM '.Fget_ap_table('tnews').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		$str_query .= ' AND a.nid = '.$nid;
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->row_array();
	}
function get_other_news($nid,$date,$nid_cat = '')
	{
		$obj_helper =& get_instance(); 
		$obj_helper->load->database();	
		$str_query = ' SELECT a.nid,a.ctitle,a.cshort_content,a.cimage_thumb,ddate01 as ddate01';
		$str_query .= ' FROM '.Fget_ap_table('tnews').' as a ';
		$str_query .= ' WHERE a.nid is not null ';
		if($nid_cat != '')
		$str_query .= ' AND a.nid_cat_news = '.$nid_cat;
		$str_query .= ' AND a.nid <> '.$nid;
		$str_query .= ' AND a.ddate01 <= "'.$date.'"';
		$str_query .= ' ORDER BY a.ddate01 desc ';
		$str_query .= ' LIMIT 0,6 ';
		$obj_result = $obj_helper->db->query($str_query);  
		return $obj_result->result_array();
	}
